<?php

class tagsComponents extends sfComponents {
	public function executeMenu(sfWebRequest $request){
		// dirty solution to get all tags in Sections Entries
		// later will be rewritten to full select with joins

		if (!empty($this->currentSection)){
			$entries=Doctrine::getTable("Entry")->createQuery()->addWhereSection($this->currentSection)->execute();
		}

		$this->tags=null;
		if (!empty($entries) && sizeof($entries)>1){ // no point to show tags, when there is only one Entry
			$this->tags=array();
			foreach ($entries as $entry){
				/* @var $entry Entry */
                $tags=$entry->getSavedTagsQuery()->execute();
				foreach ($tags as $tag){
					if (!in_array($tag, $this->tags)){
						$tag->setSection($this->currentSection);// filling tags with currentSection for Twig to get url from it later
						$this->tags[]=$tag;
					}
				}
			}
		}
	}

}
